﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;

using ProjectBase.Core;

using Survey.Common;
using Survey.Common.Business;
using Survey.Common.Business.Services;
using Survey.Common.Data;
using Survey.Entity;
using Survey.Entity.Services;

namespace Survey.Business
{
    /// <summary>
    ///     All Business checks for 'ArticleCategory' on CRUD operations
    ///     are nested and encapsulated in this ArticleCategoryFacade
    /// </summary>
    public class ArticleCategoryFacade
        : CodeListFacade<ArticleCategory, CodeListFilter, IArticleCategoryDao>,
          IArticleCategoryFacade
    {
        #region IArticleCategoryFacade Members
        public IArticleFacade ArticleFacade { protected get; set; }
        #endregion

        public virtual bool IsArticleCategoryInUse(ArticleCategory entity)
        {
            var usedBy = ArticleFacade
                .Find(new ArticleFilter { ArticleCategory = entity, MaxRowsPerPage = 1 })
                .FirstOrDefault();
            if (usedBy.Is())
            {
                this.PublishError(Str.Messages.ItemIsUsedForEntity3
                    , entity
                    , usedBy
                    , "ArticleCategory"
                    );
                return true;
            }
            return false;
        }
    }
}